package com.hushao.aimi.repository;

import com.hushao.aimi.entity.AimiProduct;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

/**
 * @description: 商品jdbc
 * @author: 胡少
 * @create: 2018-06-06 16:04
 **/
public interface ProductRepository extends JpaRepository<AimiProduct,String> {

    /**
     * 修改商品状态
     * @param productId
     * @param status
     * @return
     * @throws Exception
     */
    @Modifying
    @Query(value = "UPDATE aimi_store.aimi_product SET status=?2 WHERE id=?1",nativeQuery = true)
    int updateStatus(Integer productId, Integer status) throws Exception;

    /**
     * 商品列表分页
     * @param string
     * @param pageable
     * @return
     */
    Page<AimiProduct> findByNameLike(String string, Pageable pageable);

    /**
     * 根据商品编号查找商品
     * @param productCode
     * @return
     */
    Optional<AimiProduct> findByProductCode(String productCode);
}
